import * as actionType from './constants.js';

import {getMainData} from '../../../api/index'
import { Toast } from 'antd-mobile';

export const changeMainData = (data)=>{
    return {
        type: actionType.GET_MAINDATA,
        data: data
    }
}

export const getData = ()=>{
    Toast.show({
        icon: 'loading',
        content: '加载中…',
        duration:0
      })
    //主页的接口请求，
    return (dispatch)=>{
        getMainData()
            .then((res)=>{
                // console.log('接口',res.data.data);
                dispatch(changeMainData(res.data.data.data))
                Toast.clear()
            })
            .catch((e)=>{
                console.error(e)
            })
    }
}

export const setIndex = (data) => {
    return {
        type: actionType.SET_INDEX,
        data: data
    }
}